package com.qf.listener;


import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

@Component
@RabbitListener(queues = "dlx_queue_demo02")
public class MyDmListener {

//    @RabbitHandler
//    public void msg(String message){
//        System.out.println("消费端接收的消息为：" + message);
//    }

    @RabbitHandler
    public void msg(Message message, Channel channel, String msg){
        //接收消息
        System.out.println("消费端接收的消息为：" + msg);
        try {
            System.out.println("我拒绝签收");
        channel.basicNack(message.getMessageProperties().getDeliveryTag(),false,false);
        }catch (Exception e){
            e.printStackTrace();
            //如果出现异常，则拒绝消息 可以重回队列 也可以丢弃 可以根据业务场景来

        }

    }

}
